package com.ltzuche.web;

import java.io.File;
import java.util.Date;
import java.util.List;

import org.apache.commons.io.FileUtils;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.upload.UploadFile;
import com.ltzuche.util.DateUtil;

public class IndexController extends BaseController {
	
	public void index() {
		List<Record> list = Db.find("select * from car a left join car_info b on a.id = b.id order by b.orderby");
		setAttr("list", list);
		render("/index.jsp");
	}
	
	public void fileupload() {
		try {
			System.out.println(1);
			String dateStr = new DateUtil("yyyyMMdd").format(new Date());
			System.out.println(2);
			UploadFile file = super.getFile("files[]", dateStr);
			System.out.println(3);
			String fileName = file.getOriginalFileName();
			FileUtils.moveFileToDirectory(file.getFile()
					, new File("/usr/local/static/ltzuche/upload/"+dateStr), true);
			System.out.println(4);
			renderJson(success(dateStr+"/"+fileName));
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println(5);
			renderJson(fail("上传失败！！"));
		}
	}
	
	public void train() {
		
	}
	
	public void plane() {
		
	}
	
	public void meeting() {
		
	}
	
	public void hotel() {
		
	}
	
	public void intro() {
		
	}
	
	public void company() {
		
	}
}
